package booksystem.dao.impl;

import booksystem.dao.BaseDao;
import booksystem.dao.CartDao;
import booksystem.entity.Cart;

import java.util.List;

public class CartDaoImpl extends BaseDao<Cart> implements CartDao {
    @Override
    public List<Cart> getUserCart(String id) {
        String sql = "select * from cart where user_id=? order by id desc";
        return getBeanList(Cart.class, sql, id);
    }

    @Override
    public int addBookToCart(Cart cart) {
        String sql = "insert into cart(user_id, cover, book_id, one_price, count, all_price) value(?,?,?,?,?,?)";
        return update(sql, cart.getUser_id(), cart.getCover(), cart.getBook_id(), cart.getOne_price(), cart.getCount(), cart.getAll_price());
    }

    @Override
    public int deleteBookFromCart(int id) {
        String sql = "delete from cart where id=?";
        return update(sql, id);
    }
}
